<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        * {
            margin: 0;
            padding: 0
        }

        .box {
            height: 100vh;
            width: 100vw;
            background-color: pink;

        }

        .box1 {
            height: 200px;
            width: 200px;
        }

        img {
            width: 380px;
        }
    </style>
</head>

<body>
    <div class="box">
        <div class="box1">
            <img src="./zz.jpg" alt="">
        </div>
    </div>
</body>
<script>
    function remRefresh() {
        // 获取屏幕宽度
        let clientWidth = document.documentElement.clientWidth;

        // 将屏幕宽度750等份，
        let rem = clientWidth / 750

        // 比值赋值给根元素fontSize
        document.documentElement.style.fontSize = rem + 'px'
        document.body.style.fontSize = '12px'
    }

    // 每次屏幕大小变化就调用这个函数
    window.addEventListener('resize', () => {
        remRefresh()
    })

    // 函数防抖
    let timer
    window.addEventListener('resize', () => {
        timer && clearTimeout(timer)
        timer = setTimeout(() => {
            remRefresh()
        }, 300)
    })
</script>

</html>